package vg.modules.navigator.components.popup_menu_component.popup_menu_items;

import vg.interfaces.ll_services.data_base_service.data.graph.Graph;
import vg.modules.navigator.components.SmartTreeComponent;
import vg.services.graph_view_manager.interfaces.graph_view.AGraphView;
import vg.services.main_manager.VGMainServiceHelper;
import vg.services.plugin_manager.event_and_request.request.UIRequestAddTab;

import javax.swing.*;
import java.util.Collection;

public class OpenGraphPopupMenuItem implements IPopupMenuItem {
	// Constants
    //private static final Icon openGraphIcon;

    static {
        //openGraphIcon = new ImageIcon(FileUtils.getWorkingDir() + "data/resources/textures/workflow.png");
    }

    @Override
    public void action(Collection<JTree> trees, JTree lastSelectedTree) {
        if (lastSelectedTree == null) return;

        SmartTreeComponent.SmartTreeNode node = (SmartTreeComponent.SmartTreeNode)lastSelectedTree.getLastSelectedPathComponent();
        if (node.isGraphHeader()) {
            Graph graph = VGMainServiceHelper.graphDataBaseManager.getGraph(node.getGraphHeader().getId());
            AGraphView graphView = VGMainServiceHelper.graphViewManager.newGraphView(graph);
            UIRequestAddTab request = new UIRequestAddTab(graphView);
            VGMainServiceHelper.userInterfaceManager.sendRequest(request);
        } else {
            VGMainServiceHelper.windowMessenger.warningMessage("Selection should be a graph", "Opening of a graph");
        }
    }

    @Override
    public boolean isVisible(Collection<JTree> trees, JTree lastSelectedTree) {
        if (lastSelectedTree == null)
            return false;

        SmartTreeComponent.SmartTreeNode node = (SmartTreeComponent.SmartTreeNode)lastSelectedTree.getLastSelectedPathComponent();
        return node.isGraphHeader();
    }

    @Override
    public Icon getIcon() {
        return null;
    }

    @Override
    public String getActionName() {
        return "Open graph";
    }
}
